package com.justech.mes.v2.dao.repository;

import com.justech.mes.v2.model.MesV2EquipmentConfigureDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lin.jia
 */
@Repository
public interface MesV2EquipmentConfigureDetailRepository extends JpaSpecificationExecutor<MesV2EquipmentConfigureDetail>, JpaRepository<MesV2EquipmentConfigureDetail, Long> {

    /**
     * 查询是否存在这个参数
     *
     * @param toleranceName
     * @return
     */
    int countByToleranceNameAndBasicId(String toleranceName, Long basicId);

    /**
     * 查询公差
     *
     * @param basicId
     * @param toleranceName
     * @return
     */

    /**
     * 查询公差值
     *
     * @param basicId
     * @param toleranceName
     * @return
     */
    @Query(value = "select tolerance_data from mes_v2_equipment_configure_detail where  basic_id = ?1 and  tolerance_name =?2", nativeQuery = true)
    String findToleranceData(Long basicId, String toleranceName);

    @Query(value = "select * from mes_v2_equipment_configure_detail where  basic_id = ?1", nativeQuery = true)
    List<MesV2EquipmentConfigureDetail> findByBasicIdInMap(Long basicId);

    /**
     * 根据外键输出
     *
     * @param basicId
     */
    void deleteByBasicId(Long basicId);
}
